import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class BaseChangeWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => BaseChangeState();
}

class BaseChangeState extends State<BaseChangeWidget> {
  int _conunter = 0;

  @override
  void increment() {
    setState(() {
      _conunter++;
    });
  }
  @override
  void lessen() {
    setState(() {
      if(_conunter>0){
        _conunter--;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    //https://blog.csdn.net/qq_41614928/article/details/105912905
    //水平对齐方式  横轴对齐方式
    return
      Scaffold(
        appBar: AppBar(
          title: Text('根据用户输入改变widget'),
          centerTitle: true,
        ),
        body: Container(
          decoration: BoxDecoration(color: Colors.white),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  color: Colors.blue,
                  textColor: Colors.white,
                  onPressed: increment,
                  child: Text('点击增加',style: TextStyle(fontSize: 20),),
                ),
                RaisedButton(
                  color: Colors.blue,
                  textColor: Colors.white,
                  onPressed: lessen,
                  child: Text('点击减少',style: TextStyle(fontSize: 20),),
                ),
                Text(
                  'Count:$_conunter',
                  style: TextStyle(
                      fontSize: 25,
                      color: Colors.black,
                      //去掉文字下面黄色下划线
                      decoration: TextDecoration.none),
                ),
              ],
            ),
          ),
        ),
      );
  }
}

